home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / chain217.zip / CHAIN.ASM next >
Assembly Source File  |  1989-05-28  |  25KB  |  591 lines

  1. PAGE ,132
  2. TITLE File Chain Program, Version 2.16, 24-Dec-1986
  3.  
  4. ; Bug Fix  Version 2.17, 28 May 1989 by David Gwillim
  5. ; Subdirectories were reported as using 0 clusters with 100% waste
  6. ; Also corrected typo for pgm lines storing file size to SIZEMSB
  7. ; Changed/Added lines marked with a comment starting with ;!!
  8. ;
  9. ; Written By Steven Georgiades
  10. ;
  11. ; File Chain Program
  12. ;   Will respond with a list of the disk clusters that make up the file chain
  13. ;   for the requested file.
  14. ;
  15. ;       If you are using this program and find it of value, your
  16. ;       contribution in any amount ($5.00 suggested) will be greatly
  17. ;       appreciated.  Makes checks payable to Steven M. Georgiades.
  18. ;               Thank you.
  19. ;
  20. ;       If you have any questions or comments about this or any other
  21. ;       SMG program, call or write:
  22. ;
  23. ;               Steven M. Georgiades
  24. ;               701-H South Hayward Street
  25. ;               Anaheim, CA 92804
  26. ;               (714) 826-9549
  27. ;
  28.  
  29. CODE      SEGMENT BYTE PUBLIC 'CODE'
  30.  
  31.           ASSUME  CS:CODE,DS:CODE,ES:CODE,SS:CODE
  32.  
  33.           ORG     5CH
  34.  
  35. FCB       LABEL   BYTE
  36.  
  37.           ORG     80H
  38.  
  39. PARAM     LABEL   BYTE
  40.  
  41.           ORG     100H
  42.  
  43. CHAIN:    JMP     BEGIN
  44.  
  45. CHAINMSG1 DB      "The Chain for $"
  46. CHAINMSG2 DB      " is:",13,10,10,"$"
  47. CHAINMSG3 DB      13,10,10
  48. CHAINMSG4 DB      "Total Clusters in File =  XXXXX",13,10,10
  49. CHAINMSG5 DB      "Physical File Length = XXXXXXXX",13,10,"$" ;!!
  50. CHAINMSG6 DB      "Logical  File Length = XXXXXXXX ("
  51. PERCENT   DB      " 0.00% Waste)",13,10,"$"
  52. ISDIR     DB      'File is a SUBDIRECTORY',13,10,"$"       ;!!
  53.  
  54. LOGSZMSG  DW      OFFSET CHAINMSG6
  55.  
  56. CLSTSTR   DB      "XXXXX$"
  57. PRCNT100  DB      "100.0"
  58.  
  59. ANDSTR    DB      " , $"
  60. THRUSTR   DB      " to$"
  61.  
  62. SPECERR   DB      "Invalid File or Path Specification",7,": $"
  63. CRLF      DB      13,10,"$"
  64.  
  65. SIGNON    DB      "File Chain Program, Version 2.17",13,10                  ;!!
  66.           DB      "SMG Software",13,10
  67.           DB      "(C) Copyright 1986, 1989 Steven M. Georgiades"    ;!!
  68.           DB      13,10,13,10,"$"                                    ;!!
  69.  
  70. USAGE     DB      13,10,"Usage:",13,10,13,10                              ;!!
  71.           DB      "  CHAIN [d:][path]filename[.ext]",13,10,13,10          ;!!
  72.           DB      "    Will respond with a list of the disk clusters that make up the specified",13,10
  73.           DB      "    file.  Note that wildcards are NOT allowed.",13,10,"$"
  74.  
  75. CLSTSEC   DW      ?
  76. DIR_LEN   DW      ?
  77. DIRBUF    DW      ?
  78. DIRSEC    DW      ?
  79. DRIVE     DB      ?
  80. EOF       DW      0FF8H
  81. FATSEC    DW      ?
  82. FATSIZE   DB      3
  83. FILENAME  DB      13 DUP(0)
  84. PREV      DW      ?
  85. RANGE     DB      0
  86. SECSIZE   DW      ?
  87. SIZLSB    DW      ?
  88. SIZMSB    DW      ?
  89. STARTSEC  DW      ?
  90.  
  91. FILESPEC  DB      "$",79 DUP(0)
  92.  
  93. BEGIN:    MOV     AH,9                          ; Output Sign-On Message
  94.           MOV     DX,OFFSET SIGNON
  95.           INT     21H
  96.           MOV     AH,19H                        ; Get Default Drive
  97.           INT     21H
  98.           MOV     DRIVE,AL                      ;   and Save
  99.           MOV     SI,OFFSET PARAM               ; Set up Pointer to Parameter
  100.           LODSB                                 ; Read Parameter Length
  101.           CBW
  102.           MOV     BX,AX
  103.           MOV     BYTE PTR [SI][BX],0           ; Terminate Parameter String
  104. STRIP:    LODSB                                 ; Strip Off Leading Whitespace
  105.           CMP     AL,' '
  106.           JE      STRIP
  107.           CMP     AL,9
  108.           JE      STRIP
  109.           OR      AL,AL                         ; If End-of-Parameter, Error
  110.           JNZ     NO_ERR1
  111.           MOV     DX,OFFSET USAGE
  112.           JMP     ERROUT
  113. NO_ERR1:  DEC     SI                            ; ReUse Last Character
  114.           MOV     DI,OFFSET FILESPEC            ; Point to FileSpec Buffer
  115.           CMP     BYTE PTR [SI+1],':'           ; If 2nd Character is Colon,
  116.           JNE     GET_PATH
  117.           AND     AL,0DFH
  118.           SUB     AL,'A'                        ;   Get Drive Number
  119.           MOV     DRIVE,AL
  120.           ADD     SI,2                          ;   and Scan Past
  121. GET_PATH: MOV     AL,DRIVE                      ; Get Drive Number
  122.           ADD     AL,'A'                        ; Convert to Drive Number 
  123.           STOSB                                 ;   in FileSpec
  124.           MOV     AL,':'                        ; Add Colon to FileSpec
  125.           STOSB
  126.           CMP     BYTE PTR [SI],'\'             ; If Next Character is not '\',
  127.           JE      COPYPATH
  128.           MOV     AL,'\'
  129.           STOSB
  130.           PUSH    SI                            ;   Get Current Path to FileSpec
  131.           MOV     SI,DI
  132.           MOV     AH,47H
  133.           MOV     DL,DRIVE
  134.           INC     DL
  135.           INT     21H
  136.           POP     SI
  137.           MOV     AL,0                          ;   Find End-of-FileSpec
  138.           MOV     CX,64
  139.           REPNE   SCASB
  140.           JE      NO_ERR2
  141.           JMP     ERROR
  142. NO_ERR2:  DEC     DI
  143.           CMP     BYTE PTR [DI-1],'\'           ;   If Root DIR, Skip
  144.           JE      COPYPATH
  145.           MOV     AL,'\'                        ;   End-of-FileSpec = '\'
  146.           STOSB
  147. COPYPATH: LODSB                                 ; Copy Rest of Parameter
  148.           OR      AL,AL                         ;   to FileSpec
  149.           JZ      COPYDONE
  150.           STOSB
  151.           JMP     SHORT COPYPATH
  152. COPYDONE: MOV     AL,'$'                        ; Set End-of-FileSpec
  153.           STOSB
  154.           MOV     DX,OFFSET FILESPEC            ; Convert to Upper Case
  155.           CALL    UPPER
  156.           MOV     AL,DRIVE                      ; Read Boot Record
  157.           MOV     CX,1
  158.           MOV     DX,0
  159.           MOV     BX,OFFSET FATBUF
  160.           INT     25H
  161.           POPF
  162.           MOV     AX,FATBUF[11]                 ; Read Sector Size
  163.           MOV     SECSIZE,AX                    ;   and Save
  164.           MOV     AL,BYTE PTR FATBUF[13]        ; Read Sectors per Cluster
  165.           XOR     AH,AH
  166.           MOV     CLSTSEC,AX                    ;   and Save
  167.           MOV     CX,FATBUF[14]                 ; Read # of Reserved Sectors
  168.           MOV     AL,BYTE PTR FATBUF[16]        ; Read # of FAT's
  169.           XOR     AH,AH                         ; Convert to Word
  170.           MOV     BX,FATBUF[22]                 ; Read Sectors per FAT
  171.           MOV     FATSEC,BX
  172.           MUL     BX                            ; Calculate Total FAT Sectors
  173.           ADD     CX,AX                         ; Add to Reserved Sectors
  174.           MOV     AX,FATBUF[17]                 ; Read Number of DIR Entries
  175.           MOV     DIR_LEN,AX
  176.           PUSH    CX                            ; Calculate DIR Sectors
  177.           MOV     CL,5
  178.           SHL     AX,CL
  179.           POP     CX
  180.           MOV     BX,SECSIZE
  181.           XOR     DX,DX
  182.           DIV     BX
  183.           OR      DX,DX                         ; Adjust for Partial Sector
  184.           JZ      NO_ADD
  185.           INC     AX
  186. NO_ADD:   MOV     DIRSEC,AX                     ; Save DIR Sectors
  187.           ADD     CX,AX                         ; Add DIR Sectors to Reserved
  188.           MOV     STARTSEC,CX                   ; Save in STARTSEC
  189.           MOV     AX,FATSEC                     ; Calculate FAT Buffer Size
  190.           MOV     BX,SECSIZE
  191.           MUL     BX
  192.           MOV     BX,AX
  193.           LEA     AX,FATBUF[BX]                 ; Get DIR Buffer Pointer
  194.           MOV     DIRBUF,AX
  195.           MOV     AX,FATBUF[19]                 ; Read Total Sectors on Media
  196.           SUB     AX,CX                         ; Calculate Total Data Clusters
  197.           MOV     BX,CLSTSEC
  198.           XOR     DX,DX
  199.           DIV     BX
  200.           CMP     AX,4079                       ; If Necessary, Adjust FAT Size
  201.           JLE     FAT_OK
  202.           MOV     FATSIZE,4
  203.           MOV     EOF,0FFF8H
  204. FAT_OK:   MOV     AL,DRIVE                      ; Read FAT
  205.           MOV     CX,FATSEC
  206.           MOV     DX,1
  207.           MOV     BX,OFFSET FATBUF
  208.           INT     25H
  209.           POPF
  210.           MOV     AL,DRIVE